﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.windows.sun.sunWindow {
    import flash.events.*;
    import flash.display.*;
    import flash.text.*;
    import net.wooga.pets.utils.pool.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.views.windows.restricted.*;

    public class SunNotificationWindow extends BaseWindowView {

        private var _background:MovieClip;
        private var _textField:TextField;

        private static const ARROW_WIDTH_ON_RIGHT_SIDE_OF_BKGR:int = 75;
        private static const PADDING:int = 25;
        private static const MAX_WIDTH:int = 500;

        private static var textFieldPool:TextfieldPool;

        override public function onRemovedFromStage():void{
            IPoolable(this._textField).recyle(this.textFieldPool);
            super.onRemovedFromStage();
        }
        override public function onAddedToStage():void{
            this.setBackground();
            this.setTextFields();
            this.setMetrics();
            this.drawToScreen();
            super.onAddedToStage();
            buttonMode = true;
            mouseChildren = false;
            addEventListener(MouseEvent.CLICK, this.onClick);
        }
        private function setBackground():void{
            this._background = AssetsLibrary.getMovieClip("SunBubble");
        }
        private function setTextFields():void{
            var _local1 = 20;
            this._textField = (this.textFieldPool.allocateObject() as TextField);
            this._textField.htmlText = this.parseTagsRepriseUtils(options.textValues.body);
            this._textField.width = MAX_WIDTH;
            if (this._textField.textWidth < MAX_WIDTH){
                this._textField.width = (this._textField.textWidth + _local1);
            };
        }
        private function setMetrics():void{
            var _local1 = 4;
            var _local2:int = (this._textField.width + PADDING);
            var _local3:int = (this._textField.height + PADDING);
            this._background.width = (_local2 + ARROW_WIDTH_ON_RIGHT_SIDE_OF_BKGR);
            this._background.height = _local3;
            this._textField.x = (_local1 + ((_local2 - this._textField.width) >> 1));
            this._textField.y = (_local1 + ((_local3 - this._textField.height) >> 1));
            this.positionNextToSunFace();
        }
        private function positionNextToSunFace():void{
            this.x = ((this.stage.stageWidth - this._background.width) - 90);
            this.y = 65;
        }
        private function drawToScreen():void{
            this.addChild(this._background);
            this.addChild(this._textField);
        }
        private function get textFieldPool():TextfieldPool{
            if (SunNotificationWindow.textFieldPool == null){
				SunNotificationWindow.textFieldPool = new TextfieldPool();
            };
            return (SunNotificationWindow.textFieldPool);
        }
        private function parseTagsRepriseUtils(_arg1:String):String{
            var _local3:RegExp;
            var _local4:RegExp;
            var _local5:String;
            var _local2:String = _arg1;
            if (_local2.indexOf("</span>") != -1){
                _local3 = new RegExp(/\<span style=\"font-size:(.\d+);">/ig);
                _local4 = new RegExp(/\<span style=\"color:#[a-f0-9]{6};\">/ig);
                _local5 = _local2.replace(_local3, "<font size=\"$1\">");
                _local5 = _local5.replace(_local4, "<font color=\"#$1\">");
                _local5 = _local5.replace(/\<\/span\>/ig, "</font>");
            } else {
                return (_arg1);
            };
            return (_local5);
        }
        private function onClick(_arg1:MouseEvent):void{
            removeEventListener(MouseEvent.CLICK, this.onClick);
            close();
        }

    }
}//package net.wooga.pets.views.windows.sun.sunWindow 

import flash.text.*;
import flash.filters.*;
import net.wooga.pets.utils.pool.*;

final class TextfieldPool extends GenericPool {

    public function TextfieldPool(){
    }
    override public function createObject():IPoolable{
        return (new PoolableTextField());
    }

}
final class PoolableTextField extends TextField implements IPoolable {

    private static const FONT_NAME:String = "MyriadProFont";
    private static const FONT_SIZE:Number = 22;
    private static const FONT_COLOR:String = "0xFFFFFF";

    public static var outline:Array;
    public static var format:TextFormat;

    public function PoolableTextField():void{
        this.embedFonts = true;
        this.autoSize = TextFieldAutoSize.CENTER;
        this.defaultTextFormat = getFormat();
        this.multiline = true;
        this.wordWrap = true;
        this.selectable = false;
        this.filters = getOutline();
        this.reset();
    }
    public function recyle(_arg1:IGenericPool):void{
        _arg1.recycle(this);
    }
    public function reset():void{
        this.width = 0;
        this.htmlText = "";
    }

    private static function getFormat():TextFormat{
        if (PoolableTextField.format == null){
			PoolableTextField.format = new TextFormat();
			PoolableTextField.format.font = FONT_NAME;
			PoolableTextField.format.color = FONT_COLOR;
			PoolableTextField.format.size = FONT_SIZE;
			PoolableTextField.format.align = TextFormatAlign.CENTER;
			PoolableTextField.format.bold = true;
        };
        return (PoolableTextField.format);
    }
    private static function getOutline():Array{
        var _local1:GlowFilter;
        if (PoolableTextField.outline == null){
            _local1 = new GlowFilter(0x854200, 1, 2, 2, 50, BitmapFilterQuality.HIGH);
			PoolableTextField.outline = [_local1];
        };
        return (PoolableTextField.outline);
    }

}
